﻿using LibBinary.FileDeclaration.Text;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LibBinary.Serialization.BinaryInText
{
    public class ConditionProviderProvider : IObjectDeclarationProvider
    {
        private static ConditionProviderProvider _Instance = new ConditionProviderProvider();
        public static ConditionProviderProvider Instance { get { return _Instance; } }

        private ConditionProviderProvider()
        {
        }

        private static Dictionary<string, StructuredDeclaration> declarationDict = new Dictionary<string, StructuredDeclaration>();

        static ConditionProviderProvider()
        {
            declarationDict.Add("bool", MakeBool());
            declarationDict.Add("int", MakeIntCompare());
        }

        public StructuredDeclaration Get(string name)
        {
            return declarationDict[name];
        }

        private static StructuredDeclaration MakeBool()
        {
            return new StructuredDeclaration(new StructuredField[] {
                new StructuredField { FieldName = "index", Declaration = new PrimitiveDeclaration(PrimitiveType.Int32) },
            });
        }

        private static StructuredDeclaration MakeIntCompare()
        {
            return new StructuredDeclaration(new StructuredField[] {
                new StructuredField { FieldName = "index", Declaration = new PrimitiveDeclaration(PrimitiveType.Int32) },
                new StructuredField { FieldName = "compare", Declaration = new StringDeclaration() },
                new StructuredField { FieldName = "reference", Declaration = new PrimitiveDeclaration(PrimitiveType.Int32) },
            });
        }
    }
}
